package com.fattyCorps.common.obj.config;

import com.fattyCorps.common.enums.EHeroConsumeType;
import com.fattyCorps.common.mgr.Cfg;
import com.fattyCorps.common.obj.dto.DHeroConsume;
import com.fattyCorps.common.obj.dto.DItemConsume;
import com.fattyCorps.common.util.GameCfgUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class StarMould extends BaseCfg {
    private int star;    // 星级
    private int maxLv;   // 最大等级
    private int propIncPer;     // 升星属性整体加成
    private String consumeItems;    // 升星消耗道具
    private String consumeHeroes; // 升星消耗英雄

    public static StarMould getCfg(Cfg cfg, int star) {
        List<StarMould> cfgAll = cfg.getCfgAll(StarMould.class);
        for (StarMould starMould : cfgAll) {
            if (starMould.getStar() == star) {
                return starMould;
            }
        }

        return null;
    }

    public static int maxStar(Cfg cfg) {
        List<StarMould> cfgAll = cfg.getCfgAll(StarMould.class);
        if (cfgAll == null || cfgAll.size() == 0) {
            return 0;
        }

        return cfgAll.get(cfgAll.size() - 1).getStar();
    }

    public List<DItemConsume> itemConsume() {
        return GameCfgUtils.splitItemStr(consumeItems);
    }

    public List<DHeroConsume> heroConsume() {
        List<DHeroConsume> retList = new ArrayList<>();
        if (consumeHeroes == null || consumeHeroes.length() == 0) {
            return retList;
        }

        String[] split = consumeHeroes.split(",");

        DHeroConsume consum = null;
        for (int i = 0; i < split.length; i++) {
            if (i % 3 == 0) {
                consum = new DHeroConsume();
                consum.setType(EHeroConsumeType.valueOf(split[i]));
            } else if (i % 3 == 1) {
                consum.setStar(Integer.valueOf(split[i]));
            } else {
                consum.setNum(Integer.valueOf(split[i]));
                retList.add(consum);
            }
        }

        return retList;
    }
}
